package microcredit.gui.editor.training;

import java.awt.BorderLayout;

import microcredit.gui.editor.AbstractEditorForm;
import microcredit.gui.handler.MemberHandler;
import microcredit.gui.handler.MemberToTrainingHandler;
import microcredit.gui.selector.SelectorPanel;
import microcredit.gui.table.impl.MemberToTrainingAssignmentTableModel;
import microcredit.model.MemberToTrainingType;
import microcredit.model.TrainingType;

public class TrainingTypeMemberForm extends AbstractEditorForm<TrainingType>{

	private static final long serialVersionUID = 1L;

	private SelectorPanel<MemberToTrainingType> selector;
	
	public TrainingTypeMemberForm() {
		setLayout(new BorderLayout());
		setTitle("Members");
	}
	
	@Override
	public void apply(TrainingType e) throws Throwable {
		if (selector != null) {
			remove(selector);
		}
		MemberHandler handler = new MemberHandler.ByTrainingTypeMemberHandler(this, e);
		MemberToTrainingHandler trainingHandler = new MemberToTrainingHandler(e, handler);
		
		selector = new SelectorPanel<MemberToTrainingType>(MemberToTrainingType.class, 
				trainingHandler, 
				trainingHandler, 
				null, 
				trainingHandler,
				null, trainingHandler, trainingHandler, MemberToTrainingAssignmentTableModel.class);
		
		selector.getDeleteAction().setName("Unassign");
		
		add(selector);
	}

	@Override
	public TrainingType receive(TrainingType e) throws Throwable {
		// nothing to do
		return e;
	}
}
